﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Pandemia.Funcionalidad;
using System.ServiceModel;
using System.ServiceModel.Channels;
using Pandemia.Entidades;

namespace Pandemia.Servicios
{
    public class BaseService
    {
        protected PandemServidor Servidor { get { return PandemServidor.ObtenerInstancia(); } }

        protected string ObtenerIp()
        {
            OperationContext context = OperationContext.Current;
            MessageProperties messageProperties = context.IncomingMessageProperties;
            RemoteEndpointMessageProperty endpointProperty = messageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;

            return endpointProperty.Address.Replace(@"::1", @"127.0.0.1").Replace(@"localhost", "127.0.0.1"); ;
        }

        protected void ChequeoBasico(string token)
        {
            if (!Servidor.ValidarToken(token))
                throw new AuthenticationException();
        }
    }
}
